package com.hdl;

import org.apache.curator.RetryPolicy;
import org.apache.curator.RetrySleeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.data.Stat;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

import java.util.List;


/**
 * @author Administrator
 */
@EnableAutoConfiguration
@ComponentScan(basePackages = {"com.hdl"})
public class ClientBootstrap {
//    public static final String providerName = "UserService#sayHello#";

    public static void main(String[] args) throws Exception { // 创建一个代理对象
//        UserService service = (UserService) RpcConsumer.createProxy(UserService.class);
//        for (; ; ) {
//            Thread.sleep(2000);
//            System.out.println(service.sayHello("are you ok ?"));
//            System.out.println(service.sayHello2("张三", "你好!"));
//        }
        SpringApplication.run(ClientBootstrap.class, args);

//        CuratorFramework curatorFramework = CuratorFrameworkFactory.builder()
//                .connectString("192.168.227.131:2181")
//                .connectionTimeoutMs(5000)
//                .sessionTimeoutMs(5000)
//                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
//                .namespace("hdlrpc")
//                .build();
//        curatorFramework.start();
//
//        Stat stat = curatorFramework.checkExists().forPath("/service_provider");
//        System.out.println(stat);
//        if (stat == null){
//            curatorFramework.create().forPath("/service_provider");
//        }
//
//        List<String> list = curatorFramework.getChildren().usingWatcher(
//                (Watcher) watchedEvent -> {
//                    System.out.println("监听器执行了额");
//                    if (watchedEvent.getType() == Watcher.Event.EventType.NodeChildrenChanged){
//                        System.out.println("子节点发生了变更");
//                    }
//                }
//        ).forPath("/service_provider");
//        System.out.println(list);
//    }
    }
}